package tencent

//前缀积 * 后缀积
func productExceptSelf(nums []int) []int {
	result := make([]int, len(nums))
	result[len(nums)-1] = 1
	for i := len(nums) - 2; i >= 0; i-- {
		result[i] = result[i+1] * nums[i+1]
	}
	product := 1
	for i := 1; i < len(nums); i++ {
		product = product * nums[i-1]
		result[i] = result[i] * product
	}
	return result
}
